package com.hhsj.ui.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.Nullable;

/**
 * @author Shaohua
 * @date [2020:09:09 11:33]
 * @Discription:
 */
public class RingView extends View {
    public RingView(Context context) {
        super(context);
    }

    public RingView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public RingView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        paint.setColor(0xff00ff00);

//        Path path = new Path();
//        path.setFillType(Path.FillType.WINDING);
//        path.addCircle(getWidth() / 2, getHeight() / 2, Math.min(getWidth(), getHeight()) / 2 - 20, Path.Direction.CW);
//        canvas.clipPath(path);
//
//        path.reset();
//        path.setFillType(Path.FillType.INVERSE_WINDING);
//        path.addCircle(getWidth() / 2, getHeight() / 2, Math.min(getWidth(), getHeight()) / 2 - 30, Path.Direction.CW);
//        canvas.clipPath(path);
//        canvas.drawPath(path, paint);


        //圆环的实现方式 利用路径的叠加规则
        canvas.save();
        Path path1 = new Path();
        path1.addCircle(100, 100, 90, Path.Direction.CW);
        path1.addCircle(100, 100, 80, Path.Direction.CCW);
        canvas.drawPath(path1, paint);
        canvas.restore();

        canvas.save();
        Path path2 = new Path();
        path2.moveTo(300, 300);
        path2.lineTo(400, 300);
        path2.lineTo(400, 400);
        path2.lineTo(300, 400);
        path2.lineTo(300, 300);

        path2.moveTo(310, 310);
        path2.lineTo(310, 390);
        path2.lineTo(390, 390);
        path2.lineTo(390, 310);
        path2.lineTo(310, 310);

        canvas.drawPath(path2, paint);
        canvas.restore();

    }
}
